package com.meevle.view.components.visualization
{
	import com.meevle.model.StudioModelLocator;
	
	import flash.display.Graphics;
	import flash.events.Event;
	import flash.media.Microphone;
	
	public class MicrophonePeakVisualization extends BaseVisualization
	{
		public var lColor:uint = 0x00FF00;
		public var rColor:uint = 0xFF0000;
		private var current : Number = 0;
		protected var hInterval : Number = 0;
		private var heightInterval : uint = 0;
		
		private var vOffset : Number = 0;
		
		override protected function drawVisualization( e : Event ) : void
		{
			if( !this.visible ) return;      
			
			var g : Graphics = this.graphics;
			var i:uint
			g.clear();
			g.endFill();
			          	
			g.lineStyle( 1, 0xFFFFFF, 1);
			current=0;
			//left channel
			g.beginFill( lColor, 1 );
			
			var microphone:Microphone = StudioModelLocator.getInstance().inputDevice;
			
			if(microphone)
			{
				if(microphone.activityLevel >= 0)
				{
					current = microphone.activityLevel / 100;
				}
			}
			vOffset = (height * current);
			g.drawRect( 0, (height - vOffset), width, vOffset );
		}
		
	}
}